package com.erp.erp_servers.money.imp;

import com.erp.erp_dao.money.IReceivePaymentDao;
import com.erp.erp_entitys.User.UserEntity;
import com.erp.erp_entitys.business.req.StatisticsInfoReq;
import com.erp.erp_entitys.money.entity.ReceivePaymentEntity;
import com.erp.erp_entitys.money.req.*;
import com.erp.erp_entitys.money.rsp.*;
import com.erp.erp_servers.money.IReceivePaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : ReceivePaymentServiceImp
 * @Description : 资金管理-收款主表实现类
 * @Author : lst
 * @Date: 2020-12-04 15:00
 */
@Service
public class ReceivePaymentServiceImp implements IReceivePaymentService {

    /**
     * 注入收款主表mapper
     */
    private final IReceivePaymentDao receivePaymentDao;

    @Autowired
    public ReceivePaymentServiceImp(IReceivePaymentDao receivePaymentDao) {
        this.receivePaymentDao = receivePaymentDao;
    }


    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ReceivePaymentEntity queryById(Integer id) {
        return receivePaymentDao.queryById(id);
    }


    /**
     * 通过实体作为筛选条件查询
     *
     * @param receivePayment 实例对象
     * @return 对象列表
     */
    @Override
    public List<ReceivePaymentEntity> queryAll(ReceivePaymentEntity receivePayment) {
        return receivePaymentDao.queryAll(receivePayment);
    }


    /**
     * 通过多个id获取收款信息
     * @param ids id集合
     * @return 收款信息
     */
    @Override
    public List<ReceivePaymentEntity> getReceivePaymentByIds(List<String> ids) {
        return receivePaymentDao.getReceivePaymentByIds(ids);
    }


    /**
     * 新增数据
     *
     * @param receivePayment 实例对象
     * @return 影响行数
     */
    @Override
    public int insert(ReceivePaymentEntity receivePayment) {
        return receivePaymentDao.insert(receivePayment);
    }


    /**
     * 修改数据
     *
     * @param receivePayment 实例对象
     * @return 影响行数
     */
    @Override
    public int update(ReceivePaymentEntity receivePayment) {
        return receivePaymentDao.update(receivePayment);
    }


    /**
     * 通过主键修改标记颜色数据
     * @param receivePayment 实例对象
     * @return 影响行数
     */
    @Override
    public int updateMarkColor(ReceivePaymentEntity receivePayment) {
        return receivePaymentDao.updateMarkColor(receivePayment);
    }

    /**
     * 获取收款、退款信息集合
     * @param req 查询参数
     * @return 收款、退款信息集合
     */
    @Override
    public List<ReceivePaymentInfoRsp> getReceivePaymentInfo(ReceivePaymentListReq req) {
        return receivePaymentDao.getReceivePaymentInfo(req);
    }



    /**
     * 获取拆分信息集合
     * @param ids 收款id集合
     * @return 拆分信息集合
     */
    @Override
    public List<SplitInfoRsp> getSplitInfo(List<String> ids) {
        return receivePaymentDao.getSplitInfo(ids);
    }

    /**
     * 根据外销合同号获取结汇相关信息
     * @param contractNo 外销合同号
     * @return 结汇相关信息
     */
    @Override
    public List<BillExchangeAndCostInfoRsp> getBillExchangeInfoByContractNo(String contractNo) {
        return receivePaymentDao.getBillExchangeInfoByContractNo(contractNo);
    }


    /**
     * 退款-获取收款信息
     * @param ids 收款id
     * @return 收款信息
     */
    @Override
    public List<ReceivePaymentEntity> getRefundAmountInfo(List<String> ids) {
        return receivePaymentDao.getRefundAmountInfo(ids);
    }

    /**
     * 根据结汇单号和外销合同号获取已收款总额
     * @param invoiceNumber 结汇单号
     * @param contractNo 外销合同号
     * @return 已收款总额
     */
    @Override
    public BigDecimal getCollectionAmountSum(String invoiceNumber, String contractNo) {
        return receivePaymentDao.getCollectionAmountSum(invoiceNumber, contractNo);
    }

    /**
     * 通過外銷合同號獲取收款信息
     * @param contractNo 外銷合同號
     * @return 收款信息
     */
    @Override
    public List<ReceivePaymentEntity> getCollectionByContractNo(String contractNo) {
        return receivePaymentDao.getCollectionByContractNo(contractNo);
    }


    //***********************************************导销售合同***********************************************************


    /**
     * 获取销售合同
     * @param req 查询条件
     * @return 销售合同
     */
    @Override
    public List<ImportContractInfRsp> getImportContractInfo(ImportContractInfoReq req) {
        return receivePaymentDao.getImportContractInfo(req);
    }





    //*************************************************导结汇信息*********************************************************
    /**
     * 获取结汇关联合同信息
     * @param req 查询条件
     * @return 结汇关联合同信息
     */
    @Override
    public List<ImportExchangeInfoRsp> getImportExchangeInfo(ImportExchangeInfoReq req) {
        return receivePaymentDao.getImportExchangeInfo(req);
    }


    /**
     * 通过合同号获取结汇信息
     * @param contractNo 合同号
     * @return 结汇信息
     */
    @Override
    public List<BillExchangeInfoRsp> getBillExchangeInfo(String contractNo) {
        return receivePaymentDao.getBillExchangeInfo(contractNo);
    }


    /**
     * 通过主键修改结汇明细数据
     * @param req 结汇数据
     * @return 影响行数
     */
    @Override
    public int updateBillExchangeDetail(BillExchangeDetailReq req) {
        return receivePaymentDao.updateBillExchangeDetail(req);
    }

    @Override
    public List<UserEntity> findUser(String userCode) {
        return receivePaymentDao.findUser(userCode);
    }

    @Override
    public List<CollectionStatistics1Rsp> collectionStatistics1(CollectionStatistics1Req req) {
        List<CollectionStatistics1Rsp> p=receivePaymentDao.collectionStatistics1(req);
        return p;
    }

    @Override
    public List<CollectionStatistics2Rsp> collectionStatistics2(CollectionStatistics2Req req) {
        List<CollectionStatistics2Rsp> p=null;
        if (req.getPageType().equals("2")){//按发票应收统计价格术语不同
            p=receivePaymentDao.collectionStatistics2Diff(req);
        }else {//按发票应收款统计
            p=receivePaymentDao.collectionStatistics2(req);
        }
        return p;
    }

    @Override
    public List<CollectionStatistics3Rsp> collectionStatistics3(CollectionStatistics3Req req) {
        List<CollectionStatistics3Rsp> p=receivePaymentDao.collectionStatistics3(req);
        return p;
    }

    @Override
    public List<CollectionStatistics4Rsp> collectionStatistics4(CollectionStatistics4Req req) {
        List<CollectionStatistics4Rsp> p=receivePaymentDao.collectionStatistics4(req);
        return p;
    }

    /**
     * 本月待认领水单
     * @param req 查询条件
     * @return 本月待认领水单
     */
    @Override
    public long getBillNoCount(StatisticsInfoReq req) {
        return receivePaymentDao.getBillNoCount(req);
    }


    /**
     * FQ利润统计
     * @param req 查询条件
     * @return FQ利润统计
     */
    @Override
    public List<ProfitStatisticsRsp> getProfitStatisticsInfo(ProfitStatisticsReq req) {
        return receivePaymentDao.getProfitStatisticsInfo(req);
    }

    /**
     * 根据客户编码获取该客户收汇金额合计
     * @param customerCode 客户编码
     * @return 该客户收汇金额合计
     */
    @Override
    public BigDecimal getSumCollectionAmount(String customerCode) {
        return receivePaymentDao.getSumCollectionAmount(customerCode);
    }

    /**
     * 根据发票编号获取收款主表id(多个id以英文逗号隔开)
     * @param billNo 发票编号
     * @return 收款主表id(多个id以英文逗号隔开)
     */
    @Override
    public String getReceivePaymentId(String billNo) {
        return receivePaymentDao.getReceivePaymentId(billNo);
    }

    /**
     * 获取收款信息
     * @param req 查询条件
     * @return 收款信息
     */
    @Override
    public List<ReceivePaymentEntity> getReceivePaymentBillNoByQuery(ReceivePaymentListReq req) {
        return receivePaymentDao.getReceivePaymentBillNoByQuery(req);
    }

    /**
     * 产品统计
     * @param req 查询条件
     * @return 产品统计
     */
    @Override
    public List<ProductStatisticsRsp> getProductStatisticsInfo(ProductStatisticsReq req) {
        return receivePaymentDao.getProductStatisticsInfo(req);
    }


    @Override
    public List<CollectionStatistics6Rsp> getCollectionStatistics6List(CollectionStatistics6Req req) {
        return receivePaymentDao.getCollectionStatistics6List(req);
    }

    /**
     * 订单详情统计
     * @param req 查询条件
     * @return 订单详情
     */
    @Override
    public List<OrderDetailRsp> getOrderDetail(OrderDetailReq req) {
        return receivePaymentDao.getOrderDetail(req);
    }
}
